<?php
/**
 * @author 	 	 supfire@sohu.com
 * @copyright    ourMy.com
 * @version      1.0
 * @name 		 c.php
 * @todo 		 用户 激活
 * @final 		 2009-05-05
 */
define('IN_YCTOOL', true);//定义该文件合法性
require_once('config.php');
require_once(DIR_COMM . 'common.php');

$url = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] :'./user.php';
substr( basename($url) , 0 , 9) == 'login.php' && $url = './user.php';
//判断是否登陆
if($user->userinfo['userid'])
{
     func::obHeader('user.php');
}
$code	= isset($_GET['code']) ? $_GET['code'] : '';
$email	= isset($_GET['email']) ? $_GET['email'] : '';
$c	= isset($_GET['c']) ? $_GET['c'] : '';
$reemail	= isset($_GET['reemail']) ? $_GET['reemail'] : '';

$rs = $user->getUserInfo($email);
$userid   = $rs['userid'];

if($userid)
{
    $reuserid = $user->modifyUserId(2, $email);
}

if(!$userid)
{
    func::ShowMsg('你点击的确认链接无效或者不完整。请重新输入完整的连接。<br /><br /> <a href="./">或者注册</a>？');		
} 

$userpath = 'userdata/'.Func::getFilePath($userid, 'config');
if (file_exists($userpath.'findpsw.php'))
{
    require_once($userpath.'findpsw.php');
    $findpsw = $variable[$userid]['findpsw'];
    $psw = $variable[$userid]['psw'];
    $friendid = $variable[$userid]['friendid'];
}
if (file_exists($userpath.'reemail.php'))
{
    include_once($userpath.'reemail.php');
    $findreemail = $variablereemail[$userid]['findreemail'];
}
if($c == 1)
{
	require_once(DIR_COMM . 'sendmail.php');
	$posttext = '
<HTML><HEAD>
<TITLE>Mail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
</HEAD>
<BODY bgColor=#FFFFFF topmargin=5
leftmargin=5 style="FONT-SIZE:9pt; FONT-FAMILY:宋体">
<div>您好，'.$email.'：<br>
<br>
您刚刚注册了'.YCTOOL_HTTPHOST.'。  要完成注册，请使用此链接：<br>
<a href="http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'"
>http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'</a><br>
<br>
将帮助您与朋友进行交流并保持联系。加入'.YCTOOL_HTTPHOST.'，
<br>
<br>
</div>
</BODY></HTML>
';
	$mailtitle = YCTOOL_HTTPHOST.'注册确认';
	$mailok = SendMail($email, $mailtitle, $posttext);
	func::ShowMsg('确认您的电子邮件地址<br />我们给您发送了一封确认电子邮件至：'.$email.'。<br />点击电子邮件中的确认链接，完成注册。<br />','','./');
}
if($c == 2 && $findreemail)
{
    require_once(DIR_COMM . 'sendmail.php');
    $posttext = '
<HTML><HEAD>
<TITLE>Mail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
</HEAD>
<BODY bgColor=#FFFFFF topmargin=5
leftmargin=5 style="FONT-SIZE:9pt; FONT-FAMILY:宋体">
<div>您好：<br>
<br>
您刚刚修改了您的邮箱。需要激活才能完成修改操作，请使用此链接确认：<br>
<a href="http://'.YCTOOL_HTTPHOST.'/c.php?reemail='.$findreemail.'&email='.$email.'"
>http://'.YCTOOL_HTTPHOST.'/c.php?reemail='.$findreemail.'&email='.$email.'</a><br>
<br>
<br>
</div>
</BODY></HTML>';
    $mailtitle = YCTOOL_HTTPHOST.'修改Email确认';
    $mailok = SendMail($email, $mailtitle, $posttext);
    func::ShowMsg('确认您的电子邮件地址<br />我们给您发送了一封确认电子邮件至：'.$email.'。<br /><br />点击电子邮件中的链接，完成修改。<br /><br /><div id="messagebox_close" type=button value="Close" onclick="self.parent.tb_remove();"><img src="image/default/img_close.gif" />&nbsp;<a href="#">关闭</a></div><br /><br />');

}
if($email && $code)
{
    $email    = $rs['email'];
    $userid   = $rs['userid'];
    $active   = $rs['active'];

    if($findpsw != $code)
    {
	func::ShowMsg('该账户已经开通或者，或者你点击的确认链接无效或者不完整。<br /><br />');
    }

    if(!$active)
    {
	$active = $user->setUserActive($userid);
    }
    if($active == 1)
    {
	
	//或者通过邮箱审核时候操作下面配置。
	$userpath = Func::getFilePath2($userid, 'userdata/', 'config');
	$arr=array($userid=>array('username'=>$rs['username']));
	func::operateFile('variable', $arr, $userpath.'data', 'php', 2);
	
	if($friendid)
	{
		$rsfriend = $user->getUserInfoById($friendid);
		unset($arr);
		$friendpath = Func::getFilePath($friendid);
		$arr=array($friendid=>array('friendid'=>$friendid,'time'=>NOWTIME,'grouptype'=>'','username'=>$rsfriend['username'],'enname'=>$rsfriend['enname'],'-1'=>'','-1'=>''));
		func::operateFile('arr_all_friend', $arr, 'userdata/'.Func::getFilePath($userid).'myfriend', 'php', 2);
		unset($arr);
		$arr=array($userid=>array('friendid'=>$userid,'time'=>NOWTIME,'grouptype'=>'','username'=>$rs['username'],'enname'=>$rs['enname'],'-1'=>'','-1'=>''));
		func::operateFile('arr_all_friend', $arr, 'userdata/'.$friendpath.'myfriend', 'php', 1);

		require_once(DIR_MODEL . 'msg.class.php');
		msg::insertAction("($userid, $friendid, 1, '', ".time().", '')");

		@include_once('userdata/'.$friendpath.'config/money.php');

		$variablemoney[$friendid]["money"] = $variablemoney[$friendid]["money"] + 500;
		func::operateFile('variablemoney', $variablemoney, 'userdata/'.$friendpath.'config/money', 'php', 2);
	}

	@unlink($userpath.'findpsw.php');
require_once(DIR_COMM . 'sendmail.php');
$posttext = '
<HTML><HEAD>
<TITLE>Mail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
</HEAD>
<BODY bgColor=#FFFFFF topmargin=5
leftmargin=5 style="FONT-SIZE:9pt; FONT-FAMILY:宋体">
<div>
'.$language['sns_hellow'].'
<br>
</div>
</BODY></HTML>';
$mailtitle = '童心网注册成功';
$mailok = SendMail($email, $mailtitle, $posttext);

	$ret = $user->Login($email, $psw, 0);
	if ($ret == "USER_LOGIN_SUCCESS")
	{
	    $user->updateLogin($user->userinfo['userid']);

	    func::obHeader('user.php?action=datau');
	}
/*	
	$codeemail = '
		您的帐户'.$email.' ('.$email.')开启了！！！<br />
		您可以在下边登录. 
		';
*/
    }
}
if($email && $reemail)
{
    if($findreemail != $reemail)
    {
	func::ShowMsg('链接无效或者不完整。<br />点击此连接<a href="c.php?c=1&email='.$email.'">重新发送确认电子邮件</a>给您？ <br /><br />');	
    }
    
    if($user->modifyUserOne(2, $userid) == $email)
    {
	$active = $user->setEmail($email, $userid);
	if($active)
	{
	    $user->modifyUserDelete($email, 2, $userid);
	    $codeemail = '
		您的帐户'.$email.' ('.$email.')修改成功了！！！<br />
		您可以在下边登录. 
	    ';
	}
    }
    else
    {
    	$codeemail = $email.' ('.$email.')没有修改请求纪录！！！<br />
		您可以在下边登录. 
	    ';
    }

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;?>" />
<style>
body
{
	margin:0px;
	font-size:12px;
	font-family:Tahoma,Arial,"宋体";
	text-align:left;
	background-color:#ffffff;
	color:#336699;
}
a {font-weight:normal;color: #00bb00;}
a:hover {font-weight:normal;color: #FFFFFF; text-decoration: none; background: #00bb00; }
a:active {font-weight:normal;color: #FFFFFF; text-decoration: none; background: #ffd200; }
.font15 {font-size:15px;}
.bstrong {font-weight:bold;}
.creat{font-size:25px; font-weight:bold;height:30px;width:360px;}
#all
{
	width:600px;
	margin-left:auto;
	margin-right:auto;
	float:center;
	word-break: break-all;
}
#all_top
{
  width:600px;
  height:90px;
  margin-bottom:0px;
  float:left;
  border-bottom:1px solid #336699;
}
#all_top_btn
{
	width:260px;
	height:90px;
	margin-left:20px;
	background:url(image/default/bg_logo.gif) top left no-repeat;
	float:left;
}
#all_top_title{
  width:450px;
  height:50px;
  padding-top:40px;
  padding-left:40px;
  font-size:15px;
  float:left;
}
/*左边*/
#all_welcome
{
  width:675px;
  height:auto;
  line-height:20px;
  margin:15px 0 0 0px;
  padding:5px;
  float:left;
}
#name_div
{
  padding-left:160px;
  font-size:12px;
  float:left;
}
#detail_div
{
  padding-left:160px;
  font-size:12px;
  float:left;
}
#sendform
{
	width:89px;
	height:37px;
	margin-left:520px;
	float:left;
	background:url(image/default/creat1.gif) top right no-repeat;
}
/*右边*/
#all_recommend
{
  width:246px;
  height:auto;
  line-height:20px;
  margin:15px 15px 0 0;
  float:right;
}
.all_reco_img{
  width:240px;
  height:auto;
  border:1px solid #bbbbbb;
  padding:10px;
  float:left;
 }
#d_body_detail{
width:528px;
height:auto;
margin:0 15px 0 15px;
padding:20px 50px 20px 50px!important;
background-color:#FFFFFF;
border:1px solid #cccccc;
float:left;
}
.colorFF0000{ color:#FF0000;}
</style>
<title>code</title>
</head>
<body >
<div id="maploading" style="float:right;background-color:0000FF;color:#FFFFFF;display:block;"> 页面加载中...... </div>
<div id="all">
  <div id="allbg">
	<div id="all_detail">
	<!--主体部分-->
	  <div id="all_d_top" class="colorFF0000">
	    <br />
	     <br />
	  </div>
	  <div id="all_d_body">
	    <div id="d_body_detail">
<SCRIPT language="JavaScript">
<!--
function fEvent(sType,oInput){
	switch (sType){
		case "focus" :
			oInput.isfocus = true;
		case "mouseover" :
			oInput.style.borderColor = '#A60000';
			break;
		case "blur" :
			oInput.isfocus = false;
		case "mouseout" :
			if(!oInput.isfocus){
				oInput.style.borderColor='#97999c';
			}
			break;
	}
}

function fLoginFormSubmit()
{
	if (fTrim(document.getElementById("email").value) == "")			
	{
		document.getElementById("email_div").innerHTML = "\请输入用户名 ?";
		return false;						
	}

	if (fTrim(document.getElementById("userpass").value) == "")	
	{
		document.getElementById("userpass_div").innerHTML = "\请输入密码 ?";
		return false;						
	}
	return true;
}

function fTrim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
//-->
</SCRIPT>
<!-- login area -->
<div id="LoginDiv">

<FORM id=login style="POSITION: relative" name=login 
onsubmit="return fLoginFormSubmit();" action="login.php" method=post>
<div id="LoginBox">
<div id="login_title"></div>
<div id="login_border">
  <table border="0" cellspacing="0" cellpadding="0" align="center" >
    <tr>
      <td height="40" align="center" class="font15">
	  <?php echo $codeemail;?>
	  </td>
    </tr>
  </table>

<TABLE width="344" border=0 align="center" cellPadding=0 cellSpacing=0 bordercolor="1" class="input_box_search">
  <TR>
    <TD align=right width=128 height=40> <LABEL id="email_div">Email：</LABEL></TD>
    <TD width="216"><INPUT class=inp onBlur="fEvent('blur',this)" 
      onmouseover="fEvent('mouseover',this)" onFocus="fEvent('focus',this)" 
      onmouseout="fEvent('mouseout',this)" name=emvalue></TD></TR>
  <TR>
    <TD align=right height=40><LABEL id="userpass_div">密　码：</LABEL></TD>
    <TD><INPUT class=inp onBlur="fEvent('blur',this)" 
      onmouseover="fEvent('mouseover',this)" onFocus="fEvent('focus',this)" 
      onmouseout="fEvent('mouseout',this)" type=password name=userpass></TD></TR>
  <TR>
    <TD height=40 colspan="2" align="center"><INPUT id=remUsername type=checkbox 
      CHECKED value="1" name=cookie>
      记住邮箱
        <input id=btn1 title=直接登录 style="BORDER-RIGHT: #d6c8e1 1px solid; BORDER-TOP: #d6c8e1 1px solid; BORDER-LEFT: #d6c8e1 1px solid; LINE-HEIGHT: 20px; BORDER-BOTTOM: #d6c8e1 1px solid"  type=submit value='  登  录  ' name='  登  录  ' class="submit" /></TD>
    </TR>
  </TABLE>
<table border="0" cellspacing="0" cellpadding="0" align="center" >
  <tr>
    <td height="40" align="center"></td>
  </tr>
</table>
</div>
</div>
</form>
</div>
		</div>
	  </div>
	  
	</div>
  </div>
</div>
<script language="javascript">
<!--
	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
		window.onload = func;
	  } else {
		window.onload = function() {
		  if (oldonload) {
			oldonload();
		  }
		  func();
		}
	  }
	}
	function overWeb() {
	    document.getElementById("maploading").style.display="none";
	}
addLoadEvent(overWeb);
 //-->
</script>
</body>
</html>
